<?php
header('Access-Control-Allow-Origin:*'); 
/**
 * 查询所有的role
 */
function getRoles(){
    $roles = Mgetall("select * from role order by id desc");
    return $roles;
}
/**
 * 判断roleName是否已经存在
 */
function checkRole(String $roleName){
    $count = Mgetone("select count(*) from role where roleName = '$roleName' ");
    if ($count == 0){
        return false;
    }else{
        return true;
    }
}
/**
 * 查询出每一个role对应的人数
 */
function getRoleCount(){
    $data = Mgetall("select role.id,role.roleName,count(admin.roleid) as count from role left join admin on role.id = admin.roleId
    GROUP BY role.roleName");
    return $data;
}
/**
 * 判断当前role下的总人数
 */
function checkRoleCountById(String $id){
    $count = Mgetone("select count(admin.id) from role left join admin on role.id = admin.roleId where role.id = '$id'");
    if ($count != 0) return false;
    else return true;
}